import React, { PureComponent } from 'react';
import ShrinkLine from "@/components/charts/ShrinkLine"
import { connect } from 'dva';
import "./index.less";


@connect(({ shares }) => {
    const { halfYearDay } = shares
    return {
      halfYearDay
    }
})
class Index extends PureComponent {
    static defaultProps = {
        code: ''
    }
    constructor(props) {
        super(props);
        this.state = {
            data: {}
        };
    }
    componentDidMount = () => {
        this.getData();
    }
    getData() {
        const { code, dispatch } = this.props;
        if (code) {
            dispatch({
                type: 'shares/queryHalfYearDayKlines',
                payload: {
                    secid: `1.${code}`,
                    fields2: 'f53'
                }
            })
        }
    }
    render() {
        const { halfYearDay, code } = this.props;
        const data = halfYearDay[code] || {};
        return (
            <div className='share-box'>
                <div className='option'>
                    <div className='cancel'></div>
                </div>
                <div className='chart'><ShrinkLine data={data.klines} /></div>
                <div className='name'>{data.name}</div>
                <div className='code'>{data.code}</div>
            </div>
        )
    }
}

export default Index